import { Service } from "egg";
import { CompanyProps } from "../model/Company";

export default class CompanyService extends Service {
  /**
   * 按需查询
   */
  public findByName(company_name: string) {
    return this.ctx.model.Company.findOne({ company_name });
  }

  /**
   * 查找列表
   */
  public findList() {
    return this.ctx.model.Company.find();
  }

  /**
   * 添加数据
   * @param data 测试数据
   */
  public async add(data: CompanyProps) {
    const { ctx } = this;
    const _data: Partial<CompanyProps> = {
      ...data,
    };
    return await ctx.model.Company.create(_data);
  }
}
